package com.hq.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hq.pojo.UserInfo;
import com.hq.service.UserInfoService;
import com.hq.service.impl.UserInfoImpl;
import com.hq.utils.JSONObjectUtil;

/**
 * Servlet implementation class UpdateUserInfoServlet
 */
@WebServlet("/UpdateUserInfoServlet")
public class UpdateUserInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("UpdateUserInfo被访问");
		String id = request.getParameter("id");
		String name = request.getParameter("name");
		String image = request.getParameter("image");
		UserInfoService service = new UserInfoImpl();
		PrintWriter print = response.getWriter();
		int i = service.updateUserInfoById(getUserInfo(Integer.valueOf(id), name, image));
		print.print(JSONObjectUtil.createUpdateUserInfoResult(i));
		print.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

	private UserInfo getUserInfo(int id, String name, String image) {
		UserInfo userInfo = new UserInfo();
		userInfo.setAccount_id(id);
		userInfo.setUser_name(name);
		userInfo.setUser_image(image);
		return userInfo;
	}

}
